﻿using System;
using System.Data;
using System.Data.SqlClient;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class ShowDeptList : System.Web.UI.Page
    {
        string account = "";
        int deptID = 0;
        EmployeeBiz employeeBiz = new EmployeeBiz();
        AccountBiz accountBiz = new AccountBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
                deptID = user.DepartemntID;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }

            if (!IsPostBack)
            {

                BindGv("",  deptID);
            }
        }
        protected void BindGv(string empCode, int deptID)
        {
            DataTable dt = employeeBiz.GetLists(account,empCode, deptID);
            int r = dt.Rows.Count;
            gvList.DataSource = dt;
            gvList.DataBind();
            if (r > 0)
            {
                lbAmount.Text = "总人数：" + r.ToString();
            }
        }

        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "ShowDeptList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "您没有查询员工的权限！");
                return;
            }
            string empCode = txtSeWord.Text.Trim();
            BindGv(empCode, deptID);
        }

        protected void btnOut_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "ShowDeptList.aspx", RightChar.Out))
            {
                JSUtility.Alert(this, "您没有导出员工的权限！");
                return;
            }
            string empCode = txtSeWord.Text.Trim();
            DataTable dt = employeeBiz.GetOutLists(account, empCode, deptID);
            if (dt.Rows.Count > 0)
                ExcelUtility.ExportDsToXls(this, dt, "Employee" + deptID + ".xls");
            else
                JSUtility.Alert(this, "无数据！");
        }

        
    }
}